package zabbix

import (
	"encoding/json"
	"errors"
)

func GraphprototypeCreateData() (string,map[string]interface{}) {
	method := "graphprototype.create"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "name": "Disk space usage {#FSNAME}",
        "width": 900,
        "height": 200,
        "gitems": [
            {
                "itemid": "22828",
                "color": "00AA00"
            },
            {
                "itemid": "22829",
                "color": "3333FF"
            }
        ]
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func GraphprototypeDeleteData() (string,map[string]interface{}) {
	method := "graphprototype.delete"
	var data map[string]interface{}
	jsonstr := []byte(`[
		"652",
		"653"
	]`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func GraphprototypeGetData() (string,map[string]interface{}) {
	method := "graphprototype.get"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "output": "extend",
        "discoveryids": "27426"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func GraphprototypeUpdateData() (string,map[string]interface{}) {
	method := "graphprototype.update"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "graphid": "439",
        "width": 1100,
        "height": 400
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func GraphprototypeCreate(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := GraphprototypeCreateData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func GraphprototypeDelete(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := GraphprototypeDeleteData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}


func GraphprototypeGet(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := GraphprototypeGetData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}


func GraphprototypeUpdate(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := GraphprototypeUpdateData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}




